package com.dog.basics.admin.controller.common;


import com.baomidou.mybatisplus.core.metadata.IPage;
import com.dog.basics.bean.dto.admin.common.BannerAddDto;
import com.dog.basics.bean.dto.admin.common.BannerEditDto;
import com.dog.basics.bean.dto.admin.common.BannerFromDto;
import com.dog.basics.bean.vo.admin.common.BannerVo;
import com.dog.basics.common.annotation.SysLog;
import com.dog.basics.common.constant.SwaggerConstants;
import com.dog.basics.common.util.PageParam;
import com.dog.basics.common.util.R;
import com.dog.basics.service.common.ISysBannerService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.annotations.ApiIgnore;

import javax.validation.Valid;
import java.util.List;

/**
 * <p>
 * 轮播图 前端控制器
 * </p>
 *
 * @author fengjukang
 * @since 2019-12-13
 */
@RestController
@RequestMapping("/pc/banner")
@Api(value = SwaggerConstants.COMMON+"轮播图模块", tags = SwaggerConstants.COMMON+"轮播图模块")
@AllArgsConstructor
public class SysBannerController {

	private final ISysBannerService sjjBannerService;


	/**
	 * @Description: 分页轮播图列表
	 * @Param: BannerFromDto
	 * @return: IPage<BannerVo>
	 * @Author: wph
	 * @Date:
	 */
	@ApiOperation(value = "分页轮播图列表", notes = "pc:banner:page")
	@GetMapping
	@PreAuthorize("@pms.hasPermission('pc:banner:page')")
	public R<IPage<BannerVo>> page(PageParam page, BannerFromDto obj) {
		IPage<BannerVo> advicePageDto = sjjBannerService.getPageList(page, obj);
		return R.ok(advicePageDto);
	}

	/**
	 * @Description: 增加轮播图
	 * @Param: BannerAddDto
	 * @return: Boolean
	 * @Author: wph
	 * @Date: 2020/05/29  0027
	 */
	@SysLog("增加轮播图")
	@ApiOperation(value = "增加轮播图", notes = "pc:banner:save")
	@PostMapping
	@PreAuthorize("@pms.hasPermission('pc:banner:save')")
	public R<Boolean> save(@Valid @RequestBody BannerAddDto obj) {
		return R.ok(sjjBannerService.saveObj(obj));
	}


	/**
	 * @Description: 删除轮播图
	 * @Param: ids
	 * @return: Boolean
	 * @Author: wph
	 * @Date: 2020/05/29  0027
	 */
	@SysLog("删除轮播图")
	@ApiOperation(value = "删除轮播图", notes = "pc:banner:delete")
	@ApiImplicitParam(name = "ids", value = "标识Ids", dataType = "List<Long>", required = true)
	@DeleteMapping
	@PreAuthorize("@pms.hasPermission('pc:banner:delete')")
	public R<Boolean> delete(@RequestBody List<Long> ids) {
		return R.ok(sjjBannerService.deleteObj(ids));
	}

	/**
	 * @Description: 修改轮播图
	 * @Param: BannerEditDto
	 * @return: Boolean
	 * @Author: wph
	 * @Date: 2020/05/29  0027
	 */
	@SysLog("修改轮播图")
	@ApiOperation(value = "修改轮播图", notes = "pc:banner:edit")
	@PutMapping
	@PreAuthorize("@pms.hasPermission('pc:banner:edit')")
	public R<Boolean> edit(@Valid @RequestBody BannerEditDto obj) {
		return R.ok(sjjBannerService.editObj(obj));
	}
}
